<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组输出最大项目</title>
</head>
<body>
    

    <script>
    
        var ary = [36,20,49,76,25,92];

        /*function findMax(ary) {
            ary.sort(function(a,b){
                return a - b;
            });
            return ary[ary.length -1];
        }*/

        /*function findMax (arr) {
            var maxItem = arr[0],minItem = arr[0];
            for(var i=0;i<arr.length;i++){
                var curItem = arr[i];
                curItem>maxItem?maxItem=curItem:null;
                curItem<minItem?minItem=curItem:null;
            }
            return maxItem;
        }*/


        /*function findMax(arr) {
            return Math.max.apply(null,arr);
        }*/


        function findMax(ary){
            var max = ary[0];
            var min = ary[0];
            for(var i=0;i<ary.length;i++){
                var item = ary[i];
                item>max?max=item:null;
                item<min?min=item:null;
            }
            return {'max': max,'min': min};
        }

        console.log(findMax(ary));



        

    </script>
</body>
</html>